<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Configuration;

$app_config = App\Globals::init()->getConfig();
$entity_dir = $app_config->get('dir')->get('src').'/Game/Entity';
$proxy_dir = $app_config->get('dir')->get('src').'/Game/Proxy';

$applicationMode = 'dev';
$config = new Configuration;

if ($applicationMode == 'dev')
{
    $cache = new \Doctrine\Common\Cache\ArrayCache;
    $isDevMode = true;
    $config->setAutoGenerateProxyClasses(true);
}
else
{
    $cache = new \Doctrine\Common\Cache\ApcCache;
    $isDevMode = false;
    $config->setAutoGenerateProxyClasses(false);
}

$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver(array($entity_dir));
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir($proxy_dir);
$config->setProxyNamespace('Game/Proxy');

$dbParams = $app_config->get('database')->get('game');

$em = EntityManager::create($dbParams, $config);

App\Globals::init()->setEntityManager($em);